﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Example.Objects1;
using Example.Objects2;

namespace Example.Mappers.Tests
{
    [TestClass]
    public class WebAccountMapperTest
    {
        [TestMethod]
        public void MapTo_WebAccount2From_WebAccount1_ReturnsEquivalent()
        {
            var srcWebAccount = CreateWebAccount1();

            var dstWebAccount = srcWebAccount.ToWebAccount2();

            CustomAssert.AreEquivalent(srcWebAccount, dstWebAccount);
        }

        [TestMethod]
        public void MapFrom_WebAccount2ToNewWebAccount1_InjectsEquivalent()
        {
            var srcWebAccount = CreateWebAccount2();

            var dstWebAccount = new WebAccount1().From(srcWebAccount);

            CustomAssert.AreEquivalent(srcWebAccount, dstWebAccount);
        }

        [TestMethod]
        [ExpectedException(typeof(NullReferenceException))]
        public void MapFrom_WebAccount2ToNullWebAccount1_ThrowsException()
        {
            var srcWebAccount = CreateWebAccount2();
            
            WebAccount1 dstWebAccount = null;
            dstWebAccount = dstWebAccount.From(srcWebAccount);
        }

        public static WebAccount1 CreateWebAccount1()
        {
            return new WebAccount1()
            {
                UserName = "toto",
                EmailAddress = "toto@tata.net"
            };
        }
        public static WebAccount2 CreateWebAccount2()
        {
            return new WebAccount2()
            {
                UserName = "foo",
                EmailAddress = "foo@bar.net"
            };
        }
    }
}
